<template>
	<div>



		<van-cell title="移至货位" is-link @click="showPopup" :value="location_name" />

		<van-popup v-model="show" position="bottom" :style="{ height: '60%' }">
			<van-picker title="货位" show-toolbar :columns="columns" @confirm="onConfirm" @cancel="onCancel"
				@change="onChange" />

		</van-popup>



	</div>
</template>

<script>
	// import Cookies from 'js-cookie'
	import {
		Toast
	} from 'vant'

	import select_all_location from "../../utils/select_all_location.js"

	export default {
		name: '',
		components: {},
		props: ['warehouseId'],
		data() {
			return {
				location_name: '请选择货位',
				location_id: '',
				warehouse_id: this.warehouseId,
				show: false,
				columns: [],
				location_list: [],

			}
		},
		methods: {
			
			send_to_parent(){
				this.$emit('listenToChangeLocationEvent',{'location_id': this.location_id})
				
			},

			showPopup() {
				this.show = true;

				select_all_location(
					this.warehouse_id,
					res => {
						// console.log('xxxxxxxxxxxxxxxxxxxxxxxxx')
						// console.log(res)
						this.columns = []
						this.location_list = res
						for (let i of res){
							this.columns.push(i.location_name)
						}
					}
				)
			},

			onConfirm(value, index) {
				Toast(`当前值：${value}, 当前索引：${index}`);
				this.location_id = this.location_list[index].id
				this.location_name = this.location_list[index].location_name
				this.send_to_parent()
				
				this.show=false
			},
			onChange(picker, value, index) {
				Toast(`当前值：${value}, 当前索引：${index}`);
				this.location_id = this.location_list[index].id
				this.location_name = this.location_list[index].location_name
				this.send_to_parent()
				// this.show=false
			},
			onCancel() {
				Toast('取消');
			},



		},
		computed: {},
		watch: {
			warehouseId: function(val, oldVal) {
				// console.log(val)
				// console.log('new: %s, old: %s', val, oldVal)
				this.warehouse_id = val
			
			}
		},
		created() {},
		mounted() {



		},
	}
</script>

<style scoped lang="less">
	.cell_header_title {
		background-color: #F0F0F0;
		font-weight: 800;
	}
</style>
